home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-06 | 2.9 KB | 140 lines | [TEXT/PJMM] |
- unit MyInteruptSafeDebug;
-
- interface
-
- procedure InitInteruptSafeDebug;
- procedure FinishInteruptSafeDebug;
- procedure InteruptSafeDebug (s: str255);
- procedure InteruptSafeDebugChar (ch: char);
-
- implementation
-
- uses
- QLowLevel;
-
- const
- ourfont = geneva;
- oursize = 9;
- ourheight = 10;
- ourdescent = 2;
- max_pixelsize = 8;
- ourrows = 12;
- our_magic = $12435687;
- debug = false;
-
- type
- CharArray = packed array[char, 1..ourheight, 1..max_pixelsize] of byte;
-
- const
- WMgrPort = $9DE;
-
- type
- GrafPtrPtr = ^GrafPtr;
-
- var
- baseaddr: Ptr;
- rowbytes: integer;
- pixelsize: integer;
- ourchars: ^CharArray;
- pos, count: integer;
- row: integer;
- magic: longint;
-
- procedure InitInteruptSafeDebug;
- var
- wp: WindowPtr;
- r: rect;
- i, h, c: integer;
- ch: char;
- begin
- if debug then begin
- magic := our_magic;
- ourchars := POINTER(NewPtr(SizeOf(CharArray)));
- SetRect(r, 0, 40, 100, 100);
- wp := NewCWindow(nil, r, '', true, 0, POINTER(-1), false, 0);
- SetPort(wp);
- TextFont(ourfont);
- TextSize(oursize);
- baseaddr := CGrafPtr(wp)^.portPixMap^^.baseAddr;
- pixelsize := CGrafPtr(wp)^.portPixMap^^.pixelsize;
- rowbytes := BAND(CGrafPtr(wp)^.portPixMap^^.rowbytes, $3FFF);
- r := screenbits.bounds;
- for ch := chr(0) to chr(255) do begin
- SetRect(r, 0, 0, 100, 100);
- EraseRect(r);
- MoveTo(0, ourheight - ourdescent);
- DrawChar(ch);
- for h := 1 to ourheight do begin
- for c := 1 to pixelsize do begin
- ourchars^[ch, h, c] := BAND(AddPtrLong(baseaddr, longInt(40 + h - 1) * rowbytes + c - 1)^, $FF);
- end;
- end;
- end;
- DisposeWindow(wp);
- SetPort(GrafPtrPtr(WMgrPort)^);
- r := screenbits.bounds;
- OffsetPtr(baseaddr, longInt(r.bottom - r.top - ourheight * ourrows) * rowbytes);
- r.top := r.bottom - ourheight * ourrows;
- EraseRect(r);
- pos := 0;
- row := 0;
- count := (r.right - r.left) div 8 - 2;
- for i := 1 to count * ourrows do begin
- InteruptSafeDebugChar(' ');
- end;
- end;
- end;
-
- procedure FinishInteruptSafeDebug;
- begin
- if debug then begin
- DisposePtr(POINTER(ourchars));
- end;
- end;
-
- {$PUSH}
- {$D-}
- procedure InteruptSafeDebugChar (ch: char);
- procedure Plot (ch: char);
- var
- h, c: integer;
- begin
- for h := 1 to ourheight do begin
- for c := 1 to pixelsize do begin
- AddPtrLong(baseaddr, longInt(h - 1 + row * ourheight) * rowbytes + pos * pixelsize + c - 1)^ := ourchars^[ch, h, c];
- end;
- end;
- end;
- begin
- if debug then begin
- if magic <> our_magic then begin
- DebugStr('BANG!');
- end;
- Plot(ch);
- pos := (pos + 1) mod count;
- if pos = 0 then begin
- row := (row + 1) mod ourrows;
- end;
- Plot('•');
- end;
- end;
-
- procedure InteruptSafeDebug (s: str255);
- var
- i: integer;
- begin
- if debug then begin
- if s = '' then begin
- InteruptSafeDebugChar('*');
- end
- else begin
- for i := 1 to length(s) do begin
- InteruptSafeDebugChar(s[i]);
- end;
- InteruptSafeDebugChar('.');
- end;
- end;
- end;
- {$POP}
-
- end.